﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL.Entities;
using System.Data.SqlClient;

namespace DAL.EntitiesDAL
{
    public class NangluongDAL : BaseDAL, UTL.IBaseDAL
    {
        #region Implement

        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_Nangluong");
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            var sql = "sp_Delete_Nangluong {0}";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }



        public bool Insert(object obj)
        {
            var o = (Nangluong)obj;
            var sql = "set dateformat dmy; execute sp_Insert_Nangluong '{0}', N'{1}', N'{2}', '{3}' ";
            sql = string.Format(sql, o.STT_QDNL, o.NOIDUNG_NL, o.NOIRA_QDNL, o.NGAYRA_QDNL.ToString("dd/MM/yyyy"));
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Nangluong)obj;
            var sql = "set dateformat dmy; execute sp_Update_Nangluong '{0}', N'{1}', N'{2}', '{3}' ";
            sql = string.Format(sql, o.STT_QDNL, o.NOIDUNG_NL, o.NOIRA_QDNL, o.NGAYRA_QDNL.ToString("dd/MM/yyyy"));
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            var sql = @"Select * from tb_Nangluong";
            sql = string.Format(sql, name);
            return ExecuteQuery(sql);
        }

        public DataTable Search(DAL.Entities.Nangluong o)
        {
            string sql;
            if (o.STT_QDNL != "")
                sql = @"Select * from tb_Nangluong Where STT_QDNL like '%" + o.STT_QDNL + "%'  ";
            else if (o.NOIDUNG_NL != "")
                sql = @"Select * from tb_Nangluong Where NOIDUNG_NL like N'%" + o.NOIDUNG_NL + "%'";
            else
                sql = @"Select * from tb_Nangluong NOIRA_QDNL like N'%" + o.NOIRA_QDNL + "%' ";

            return ExecuteQuery(sql);
        }

        #endregion

        #region Other

        public DataTable Select_Max()
        {
            var sql = @"Select Max(STT_QDNL) as Ma From tb_Nangluong";
            return ExecuteQuery(sql);
        }

        #endregion
    }
}
